﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FATCATool
{
    public partial class Form1 : Form
    {
        private FATCA_OECD _filing;

        public Form1()
        {
            InitializeComponent();
        }

        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            if (dlgOpenFile.ShowDialog() == DialogResult.OK)
            {
                _filing = FATCASchema.Utilities.XMLDeserializer.DeserializeObjectFromFile<FATCA_OECD>(dlgOpenFile.FileName);
                fatcaContainer.Initialize(_filing);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (_filing == null)
                return;

            bool result = _filing.GenerateXML();

            if (result)
            {
                if (dlgSaveFile.ShowDialog() == DialogResult.OK)
                {
                    _filing.SaveXML(dlgSaveFile.FileName);
                }
            }
            else
            {
                MessageBox.Show(_filing.ValidationMessages.ToString());

            }
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            _filing = FATCA_OECD.NewFiling();
            fatcaContainer.Initialize(_filing);
        }


        private void btnSample_Click(object sender, EventArgs e)
        {
            _filing = FATCA_OECD.NewSampleFiling(10, 10);
            fatcaContainer.Initialize(_filing);
        }
    }
}
